home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / e / kyz_obj.lha / test / catalog / README < prev   
Text File  |  1998-09-03  |  2KB  |  60 lines

  1. CATALOG OBJECT
  2.  
  3. What is localization?
  4.  
  5. On the Amiga, it's the ability for programs to adapt to the locale in which
  6. they  are  situated.  This  includes  minor  things like how money and time
  7. values   are   handled,   string  routines  being  aware  of  international
  8. characters, and so on. But the major part of localization is the ability to
  9. appear entirely in the user's preferred language.
  10.  
  11. How is this done? Well, normally programs use 'strings', like so:
  12.  
  13. WriteF('What is your name?\nName: ')
  14. ReadStr(stdin, name)
  15. WriteF('Hello \s!\n', name)
  16.  
  17. The  first  string  is  literal,  the second is a formatting string. We can
  18. introduce  a  mechanism  to swap these strings for a magic number, which we
  19. can give to a function to return the string itself.
  20.  
  21. CONST WHAT_IS_YOUR_NAME, HELLO_USER
  22.  
  23. WriteF(getstr(WHAT_IS_YOUR_NAME))
  24. ReadStr(stdin, name)
  25. WriteF(getstr(HELLO_USER), name)
  26.  
  27. PROC getstr(id)
  28.   SELECT id
  29.   CASE WHAT_IS_YOUR_NAME; RETURN 'What is your name?\nName: '
  30.   CASE HELLO_USER;        RETURN 'Hello \s!\n'
  31.   ENDSELECT
  32. ENDPROC
  33.  
  34. Now  we have done that, this getstr() function is free to either return the
  35. original  string,  or  change  it  for  another one. What the full getstr()
  36. function does is use locale.library to look up a 'catalog', if there is one
  37. for  the  user's  preferred  language,  if  the ones built into the program
  38. ('default strings') aren't the appropriate language in the first place.
  39.  
  40. If  you  have  not read the docs to locale.library, the docs of CatComp, or
  41. the docs of FlexCat, then do so now.
  42.  
  43. You  have  to remove all strings from your program, and replace them with a
  44. call  to a function with a named ID (like HELLO_USER as before), then write
  45. a  'catalog  descriptor'  (.cd)  file  with these named IDs and the default
  46. strings for those IDs.
  47.  
  48. Now,  you  use  a program to generate code from that .cd file, which writes
  49. the  getstr() function, the code to define all the ID constants, and stores
  50. all the real strings.
  51.  
  52. At this point, it is easiest to use the source-generator FlexCat. Make an E
  53. source  from  your  catalog,  using  the  provided 'E.sd' file, then simply
  54. compile  it  and  use  it  in  your  program in the same way as the example
  55. 'helloworld_test.e'.
  56.  
  57. If  you  don't use FlexCat (more fool you), basically all you have to do is
  58. create an instance of catalog_obj, open your catalog with it, and provide a
  59. block of default id/string pairs - see the included autodocs.
  60.